﻿namespace MauiApp1
{
    public class PageIconDrawable : IDrawable
    {
        public Color? BackColor { get; set; }
        public Color? ForceColor { get; set; }
        public PageIcons IconType { get; set; }
        public float? StrokeSize { get; set; }


        public void Draw(ICanvas canvas, RectF dirtyRect)
        {
            canvas.SaveState();
            canvas.StrokeColor = ForceColor ?? Colors.White;
            canvas.StrokeSize = StrokeSize ?? 1f;
            float size = Math.Min(dirtyRect.Width, dirtyRect.Height);                   
            var radius = size / 2;            
            canvas.FillColor = BackColor ?? Colors.Transparent;
            canvas.FillCircle(dirtyRect.Center.X, dirtyRect.Center.Y, radius);
            switch (IconType)
            {
                case PageIcons.FirstPage:
                    DrawFirstPage(canvas, dirtyRect);
                    break;
                case PageIcons.GoPrevious:
                    DrawGoPrevious(canvas, dirtyRect);
                    break;
                case PageIcons.GoNext:
                    DrawGoNext(canvas, dirtyRect);
                    break;
                case PageIcons.LastPage:
                    DrawLastPage(canvas, dirtyRect);
                    break;
                default:
                    break;
            }            
            canvas.ResetState();
        }

        private void DrawFirstPage(ICanvas canvas, RectF dirtyRect)
        {
            PathF path = new PathF();
            float centerY = dirtyRect.Height / 2;
            float x, y;
            //左侧竖线
            x = dirtyRect.Width * 0.3f;
            y = dirtyRect.Height * 0.25f;
            path.MoveTo(x, y);
            y = dirtyRect.Height * 0.75f;
            path.LineTo(x, y);
            //右侧上半部         
            x = dirtyRect.Width * 0.4f;
            y = centerY + 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.7f;
            y = dirtyRect.Height * 0.25f;
            path.LineTo(x, y);
            //右侧下半部
            x = dirtyRect.Width * 0.4f;
            y = centerY - 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.7f;
            y = dirtyRect.Height * 0.75f;
            path.LineTo(x, y);
            //写入
            canvas.DrawPath(path);
        }

        private void DrawLastPage(ICanvas canvas, RectF dirtyRect)
        {
            PathF path = new PathF();
            float centerY = dirtyRect.Height / 2;
            float x, y;
            //右侧竖线
            x = dirtyRect.Width * 0.7f;
            y = dirtyRect.Height * 0.25f;
            path.MoveTo(x, y);
            y = dirtyRect.Height * 0.75f;
            path.LineTo(x, y);
            //左侧上半部         
            x = dirtyRect.Width * 0.6f;
            y = centerY + 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.3f;
            y = dirtyRect.Height * 0.25f;
            path.LineTo(x, y);
            //右侧下半部
            x = dirtyRect.Width * 0.6f;
            y = centerY - 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.3f;
            y = dirtyRect.Height * 0.75f;
            path.LineTo(x, y);
            //写入
            canvas.DrawPath(path);
        }

        private void DrawGoNext(ICanvas canvas, RectF dirtyRect)
        {
            PathF path = new PathF();
            float centerY = dirtyRect.Height / 2;
            float x, y;            
            //左侧上半部         
            x = dirtyRect.Width * 0.65f;
            y = centerY + 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.35f;
            y = dirtyRect.Height * 0.25f;
            path.LineTo(x, y);
            //右侧下半部
            x = dirtyRect.Width * 0.65f;
            y = centerY - 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.35f;
            y = dirtyRect.Height * 0.75f;
            path.LineTo(x, y);
            //写入
            canvas.DrawPath(path);
        }

        private void DrawGoPrevious(ICanvas canvas, RectF dirtyRect)
        {
            PathF path = new PathF();
            float centerY = dirtyRect.Height / 2;
            float x, y;
            //左侧上半部         
            x = dirtyRect.Width * 0.35f;
            y = centerY + 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.65f;
            y = dirtyRect.Height * 0.25f;
            path.LineTo(x, y);
            //右侧下半部
            x = dirtyRect.Width * 0.35f;
            y = centerY - 0.5f;
            path.MoveTo(x, y);
            x = dirtyRect.Width * 0.65f;
            y = dirtyRect.Height * 0.75f;
            path.LineTo(x, y);
            //写入
            canvas.DrawPath(path);
        }
    }
}
